package com.gnerv.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gnerv.cms.entity.Content;
import com.gnerv.cms.mapper.ContentMapper;
import com.gnerv.cms.service.IContentService;
import com.gnerv.cms.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * CMS平台-文章内容表 服务实现类
 * </p>
 *
 * @author Gnerv LiGen
 * @since 2019-07-01
 */
@Service
public class ContentServiceImpl extends ServiceImpl<ContentMapper, Content> implements IContentService {

    @Autowired
    ContentMapper contentMapper;

    @Override
    public boolean createContent(Content content) {
        String cId = UUIDUtil.getLower();
        content.setbId(cId);
        contentMapper.insert(content);
        return true;
    }

    @Override
    public boolean deleteContent(String bId) {
        contentMapper.delete(new QueryWrapper<>(new Content(bId)));
        return true;
    }

    @Override
    public boolean deleteContentByAid(String aId) {
        contentMapper.delete(new QueryWrapper<>(new Content(null, aId)));
        return true;
    }

    @Override
    public boolean updateContent(Content content) {
        contentMapper.update(content, new QueryWrapper<>(new Content(content.getbId())));
        return true;
    }

    @Override
    public Content selectContent(String bId) {
        Content content = contentMapper.selectOne(new QueryWrapper<>(new Content(bId)));
        return content;
    }

    @Override
    public List<Content> listContent(Content content) {
        List<Content> contents = contentMapper.selectList(new QueryWrapper<>(content));
        return contents;
    }

    @Override
    public Content selectContentByAid(String aId) {
        Content content = contentMapper.selectOne(new QueryWrapper<>(new Content(null, aId)));
        return content;
    }
}
